package cn.occgmat.service.impl;

import cn.occgmat.entity.RbsystemStation;
import cn.occgmat.dao.RbsystemStationDao;
import cn.occgmat.service.RbsystemStationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车站信息表(RbsystemStation)表服务实现类
 *
 * @author shimmer
 * @since 2021-03-27 15:36:45
 */
@Transactional(rollbackFor = Exception.class)
@Service("rbsystemStationService")
public class RbsystemStationServiceImpl implements RbsystemStationService {
    @Resource
    private RbsystemStationDao rbsystemStationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param stationId 主键
     * @return 实例对象
     */
    @Override
    public RbsystemStation queryById(Integer stationId) {
        return this.rbsystemStationDao.queryById(stationId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<RbsystemStation> queryAllByLimit(int offset, int limit) {
        return this.rbsystemStationDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param rbsystemStation 实例对象
     * @return 实例对象
     */
    @Override
    public RbsystemStation insert(RbsystemStation rbsystemStation) {
        this.rbsystemStationDao.insert(rbsystemStation);
        return rbsystemStation;
    }

    /**
     * 修改数据
     *
     * @param rbsystemStation 实例对象
     * @return 实例对象
     */
    @Override
    public RbsystemStation update(RbsystemStation rbsystemStation) {
        this.rbsystemStationDao.update(rbsystemStation);
        return this.queryById(rbsystemStation.getStationId());
    }

    /**
     * 通过主键删除数据
     *
     * @param stationId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer stationId) {
        return this.rbsystemStationDao.deleteById(stationId) > 0;
    }

    @Override
    public Integer getCount() {
        return this.rbsystemStationDao.getCount();
    }
}
